def usr_dict_base():
    """
    字典基础操作
    :return:
    """
    xiaoming_dict = {"name": "小明"}
    print(id(xiaoming_dict))

    # 1.取值
    # 由键得到对应的值
    print(xiaoming_dict["name"])

    # 2.增加、修改
    # 若无该键，则添加：若有该建，则修改该建对应的值
    xiaoming_dict["age"] = 21
    print(xiaoming_dict)
    xiaoming_dict["gender"] = "male"
    xiaoming_dict["name"] = "小小明"
    print(xiaoming_dict)

    # 3.删除
    # pop的返回值是删除的键对应的值
    print(xiaoming_dict.pop("gender"))
    # del删除对应的键值对
    del xiaoming_dict["name"]
    print(xiaoming_dict)

    # 4.len统计并返回字典中的键值对个数
    print(len(xiaoming_dict))

    # 5.合并字典
    new_dict = {"height": 1.75, "age": 23}
    # updata用于合并两字典，若被合并的字典中有重复的键，则更新改键对应的值
    #                    若出现新键，则加入新的键值对
    xiaoming_dict.update(new_dict)
    print(xiaoming_dict)

    # 6.clear清空字典
    xiaoming_dict.clear()
    print(f"字典{xiaoming_dict},地址{id(xiaoming_dict)}")


def usr_dict_iter():
    """
    字典遍历
    :return:
    """
    xiaoming_dict = {"name": "小明", "qq": "123456", "phone": "10086"}

    # 每次遍历得到字典的键
    for k in xiaoming_dict:
        print(k, xiaoming_dict[k])
    print("*" * 50)

    # k,v对得到的键值对进行拆包
    for k, v in xiaoming_dict.items():
        print(k, v)
    print("*" * 50)

    # 每次遍历得到字典的键
    for k in xiaoming_dict.keys():
        print(k)
    print("*" * 50)

    # 每次遍历得到字典的值
    for v in xiaoming_dict.values():
        print(v)


def usr_list_dic():
    """
    列表中存储字典
    :return:
    """
    card_list = [{"name": "张三", "qq": "12345", "phone": "110"}
        , {"name": "李四", "qq": "54321", "phone": "10086"}]
    for card in card_list:
        print(card, type(card))


def usr_unpack_package():
    """
    解包
    :return:
    """
    k, v, w = (1, 2, 3)
    print(k, v, w)


if __name__ == '__main__':
    # usr_dict_base()
    # usr_dict_iter()
    # usr_list_dic()
    usr_unpack_package()
